/*
* Copyright (c) 2008-2011, Thomas Handorf
* 
* This file is part of libScopes.
* libScopes is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* libScopes is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public License
* along with libScopes.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifdef SCOPES_USEBOOSTSERIALIZATION
#include <boost/archive/text_oarchive.hpp> 
#include <boost/archive/text_iarchive.hpp> 
#endif // SCOPES_USEBOOSTSERIALIZATION
#include "array.h"
#include "net.h"
#include "scopes.h"
#include "findseeds.h"
#include <iostream> 
#include <sstream> 
void test(const std::string& str1,const char* str2,const char* msg){
   printf("%s",msg);
   printf("...");
   if (str1.compare(str2)==0){
      printf("ok");
   } else {
      printf("fail: ");
      std::cout << str1;
   }
   printf("\n");
}

int main(){
   /*
   c0+c1->c2,c3+c2->c4+c5,c1->c6
   // memory leaks ahead!!!!
   */ 
   Net* net=new Net;
   net->addRea(new VS(2,(size_t[]){0,1}),new VS(1,(size_t[]){2}));
   net->addRea(new VS(2,(size_t[]){3,2}),new VS(2,(size_t[]){4,5}));
   net->replaceRea(2,new VS(1,(size_t[]){1}),new VS(1,(size_t[]){6}));
   VS* idx=new VS(7,(size_t[]){0,1,2,3,4,5,6});
   VC* tgt=new VC(7,(unsigned char[]){1,1,1,1,1,1,1});
   VC* seed=findseed(net,idx,tgt);
   //printf("seed for rev, def order\n");
   seed->print();
   test(seed->printToString(),"[0 0 0 0 1 1 0]","seed for rev, def order");
   delete idx;
   delete seed;
   idx=new VS(7,(size_t[]){4,5,0,1,2,3,6});
   seed=findseed(net,idx,tgt);
   //printf("seed for rev, alt order\n");
   seed->print();
   test(seed->printToString(),"[0 0 1 1 0 0 0]","seed for rev, alt order");
   delete net;
   delete idx;
   delete seed;
   // irreversible
   net=new Net;
   net->addRea(new VS(2,(size_t[]){0,1}),new VS(1,(size_t[]){2}),1);
   net->addRea(new VS(2,(size_t[]){3,2}),new VS(2,(size_t[]){4,5}),1);
   net->replaceRea(2,new VS(1,(size_t[]){1}),new VS(1,(size_t[]){6}),1);
   idx=new VS(7,(size_t[]){0,1,2,3,4,5,6});
   seed=findseed(net,idx,tgt);
   //printf("seed for irrev, def order\n");
   seed->print();
   test(seed->printToString(),"[1 1 0 1 0 0 0]","seed for irrev, def order");
   return 0;
}
